package com.lxz.aiagentbackend.controller;

import com.lxz.aiagentbackend.app.FitnessCoachApp;
import com.lxz.aiagentbackend.app.YuManus;
import jakarta.annotation.Resource;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.ai.tool.ToolCallback;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import reactor.core.publisher.Flux;

@RestController
@RequestMapping("/ai")
public class AiController {

    @Resource
    private FitnessCoachApp fitnessCoachApp;

    @Resource
    private ToolCallback[] allTools;

    @Resource
    private ChatModel dashscopeChatModel;



    @GetMapping("/chat/sync")
    public String doChatWithFitnessCoachAppSync(String message, String chatId) {
        return fitnessCoachApp.doChatWithTools(message, chatId);
    }

    /**
     * @description: ai健身教练
     * @author: liuxinzhi
     * @date: 2025/9/14 11:05
     * @param: [message, chatId]
     * @return: reactor.core.publisher.Flux<java.lang.String>
     **/
    @GetMapping(value = "/chat/sse", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<String> doChatWithFitnessCoachAppSSE(String message, String chatId) {
        return fitnessCoachApp.doChatByStream(message, chatId);
    }

    /**
     * 流式调用 Manus 超级智能体
     *
     * @param message
     * @return
     */
    @GetMapping("/agent/chat")
    public SseEmitter doChatWithAgent(String message) {
        YuManus yuManus = new YuManus(allTools, dashscopeChatModel);
        return yuManus.runStream(message);
    }
}
